<template>
	<view class="page" v-if="!loadding" :style="{minHeight:windowHeight+'px'}">
		
		<view class="top-head">
			<view class="head-l">
				<image src="../../../static/app/jiaotou1.png" @click="gotoPage('/pages/user/index/index')" mode=""></image>
			</view>
			<view class="head-title">我的车辆</view>
			<view class="head-r" @click="gotoPage('/pages/user/add-mycar/add-mycar')">+ 添加车辆</view>
		</view>
		
		<view class="car-wrap">
			<view class="car-list">	
				<!-- @click="gotoPage('/pages/user/my-car/journey/journey')" -->
				<view class="car-item" v-for="(item,index) of car">
					<view class="car-pic" @click="gotoDetail(item.car_id,item.status)">
						<image :src="item.car_info4" mode="" ></image>
						<!-- <image src="../../../static/app/logo.png" mode=""></image> -->
					</view>
					<view class="car-info">
						<view class="car-item-head" @click="gotoDetail(item.car_id,item.status)">
							<view>{{item.type_name}}</view>
							
							<!-- <view>小型客车</view> -->
							<text v-if="item.status == -1" >已注销</text>
							<text v-if="item.status == 0" style="color: #5864FD">审核中</text>
							<text v-if="item.status == 1" >审核通过</text>
							<text v-if="item.status == 2" style="color: #FF6159;" >审核不通过</text>
						</view>
						<!-- <view class="car-number">桂C 123456</view> -->
						<view class="car-number" @click="gotoDetail(item.car_id,item.status)">{{item.car_number}}</view>
						<view class="car-item-bottom">
							<text>司机：{{item.drivername}}</text>
							<image class="delete" @click="deleteCar(item.car_id)" src="../../../static/delete.png" mode=""></image>
						</view>
					</view>
				</view>
				
				<!-- <view class="car-item">
					<view class="car-pic">
						<image src="../../../static/app/logo.png" mode=""></image>
					</view>
					<view class="car-info">
						<view class="car-item-head">
							<view>小型客车</view>
							<text>审核中</text>
						</view>
						<view class="car-number">桂C 123456</view>
						<view class="car-item-bottom">
							<text>司机：吴彦祖</text>
							<image src="../../../static/app/jiaotou.png" mode=""></image>
						</view>
					</view>
				</view> -->
			</view>
		</view>
		<!-- 没有记录 -->
		<view class="nullmsg d-c-c p30" v-if="car.length == 0">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<!-- <uni-load-more class="not" v-else :loadingType="loadingType"></uni-load-more> -->
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				loadding:false,
				car:'',
				windowHeight:'',
			};
		},
		onShow() {
			/*获取数据*/
			this.getData();
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
				}
			});
		},
		onPullDownRefresh() {
			this.getData();
			setTimeout( () => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		computed: {
			/*加载中状态*/
			loadingType() {
				if (this.loadding) {
					return 1;
				} else {
					if (this.driver.length != 0) {
						return 2;
					} else {
						return 0;
					}
				}
			}
		},
		methods:{
			gotoDetail(car_id,status){
				//console.log(status)
				if(status == 1){
					uni.navigateTo({
						url:'/pages/user/my-car/journey/journey?select=1&&car_id='+car_id
					})
				}else{
					uni.navigateTo({
						url:'/pages/user/my-car/updata/updata?select=1&&car_id='+car_id
					})
				}
				// else if(status == 0){
				// 	uni.showModal({
				// 		title:'该车辆正在审核中'
				// 	})
				// }else{
				// 	uni.showModal({
				// 		title:'该车辆审核未通过'
				// 	})
				// }
			},
			/* 删除车辆 */
			deleteCar(car_id){
				let self = this;
				uni.showModal({
					title:'是否要删除车辆信息',
					success: function (res) {
					       if (res.confirm) {
					           self._post('car.index/del_car',
					           {
					           	car_id:car_id
					           },
					            function(res) {
									self.getData();
					           });
					       } else if (res.cancel) {
							   
					       }
					   }
				})
				console.log(car_id)				 				
			},
			/*获取数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				// self._get('user.index/detail', {}, function(res) {
				// 	console.log(res);
				// 	console.log("112")
				// 	self.detail = res.data.userInfo;
				// 	self.loadding = false;
				// });
				self._get('user.index/my_car', {}, function(res) {
					self.car = res.data.car;
					
					
					
					
					// self.loadding = false;
					uni.hideLoading();
				});
			},
			/*跳转页面*/
			gotoPage(path) {
				let self = this;
				if(path.startsWith('/')){
					uni.navigateTo({
						url: path
					});
				}else{
					self[path]();
				}
			},			
		}
	}
</script>

<style lang="scss">
	@import 'my-car.scss';
</style>
